#ifndef __OSTMR_H__
#define __OSTMR_H__

/*********************************************************************
 * INCLUDES
 */

#ifdef __cplusplus
extern "C" {
#endif

#include "thread.h"

/*********************************************************************
 *  EXTERNAL VARIABLES
 */

#if (SAL_OSTMR == _ENABLE)

/*********************************************************************
 * MACROS
 */


/*********************************************************************
 * TYPES
 */

/// \details Timer ID identifies the timer.
typedef void *osTimerId_t;

/// Entry point of a timer call back function.
typedef void (*osTimerFunc_t) (void *argument);

/// Timer type.
typedef enum {
  osTimerOnce               = 0,          ///< One-shot timer.
  osTimerPeriodic           = 1           ///< Repeating timer.
} osTimerType_t;

/// Attributes structure for timer.
typedef struct {
  const char                   *name;   ///< name of the timer
  uint32_t                 attr_bits;   ///< attribute bits
  void                      *cb_mem;    ///< memory for control block
  uint32_t                   cb_size;   ///< size of provided memory for control block
} osTimerAttr_t;

typedef struct _os_timer_base
{
    osTimerId_t(*pfOSTimerNew)(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
    const char*(*pfOSTimerGetName)(osTimerId_t timer_id);
    osStatus_t (*pfOSTimerStart)(osTimerId_t timer_id, uint32_t time_ms);
    osStatus_t (*pfOSTimerStop)(osTimerId_t timer_id);
    uint32_t   (*pfOSTimerIsRunning)(osTimerId_t timer_id);
    osStatus_t (*pfOSTimerDelete)(osTimerId_t timer_id);
} OSTIMER_BASE_S;

/*********************************************************************
 * FUNCTIONS
 */

//  ==== Timer Management Functions ====

/**
 *   @Description: 系统时间定时器模块安装
 *   @param : NA
 *   @return: _OK/_ERR
 */
int32_t osTimerInstall(void);

/**
 *   @Description: 系统定时器模块卸载
 *   @param : NA
 *   @return: _OK/_ERR
 */
int32_t osTimerUninstall(void);

/// Create and Initialize a timer.
/// \param[in]     func          start address of a timer call back function.
/// \param[in]     type          osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
/// \param[in]     argument      argument to the timer call back function.
/// \param[in]     attr          timer attributes; NULL: default values.
/// \return timer ID for reference by other functions or NULL in case of error.
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);

/// Get name of a timer.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
/// \return name as NULL terminated string.
const char *osTimerGetName (osTimerId_t timer_id);

/// Start or restart a timer.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
/// \param[in]     time_ms
/// \return status code that indicates the execution status of the function.
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t time_ms);

/// Stop a timer.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osTimerStop (osTimerId_t timer_id);

/// Check if a timer is running.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
/// \return 0 not running, 1 running.
uint32_t osTimerIsRunning (osTimerId_t timer_id);

/// Delete a timer.
/// \param[in]     timer_id      timer ID obtained by \ref osTimerNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osTimerDelete (osTimerId_t timer_id);

#endif  //(SAL_TIMER == _ENABLE)

#ifdef __cplusplus
}
#endif /* end of __cplusplus */

#endif

/************************************** The End Of File **************************************/

